package com.sinosoft.util;

import java.security.MessageDigest;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sinosoft.exception.ComplainException;

import sun.misc.BASE64Encoder;

public class MD5Util {

	private static Logger logger = LoggerFactory.getLogger(MD5Util.class);
	public static String md5(String str) {
		if (StringUtils.isBlank(str))
			return null;
		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			BASE64Encoder encoder = new BASE64Encoder();
			return encoder.encode(md5.digest(str.getBytes("UTF-8")));
		} catch (Exception e) {
			logger.error("MD5加密异常！", e);
			throw new ComplainException("MD5加密异常！", e);
		}
	}
}
